public  with sharing  abstract class WBController {
	// ---------------- property start ------------------
	public string screen_name{get;set;}
	public string objectId{get;set;}
	public string keyword{get{if(WBUtil.isNvl(keyword))return screen_name;else return keyword;}set;}
	public List<WB_OpenApi.WB_search_suggestions_users_out> user_list{get{
		if(user_list==null)
			user_list = new List<WB_OpenApi.WB_search_suggestions_users_out>();
		return user_list;
	}set;}
	public integer user_list_size{get{return user_list.size();}set;}
	public WB_OpenApi.WB_users_show_out user_profile{get;set;}
	public string object_Id{get;set;}
	public string weibo_uid{get;set;}
	
	// ---------------- property end ------------------
  public PageReference redirect(){
  	PageReference p = null;
		string weibo_code = WBSfdcInfo.instance().code;
		if(WBUtil.isNvl(weibo_code)){
			p = Page.WBLeadLogin;
		}
		else if(WBUtil.isNvl(weibo_uid)){
    	p = Page.WBLeadSelectUser;
		}
    else{
    	p = Page.WBLeadContent;
    }
		p.setRedirect(true);
		p.getParameters().put('id',object_Id);
		return p;
  }

	// ---------------- Select user Page ------------------

	public void search_suggestions_users(){
		try{
			WB_OpenApi.WB_search_suggestions_users_in wb_in = new WB_OpenApi.WB_search_suggestions_users_in();
			wb_in.q = keyword;
			wb_in.count = 50;
			string req = wb_in.toRequestUrl();
			string jsonResult = WBUtil.sendRequest(req);
			if(jsonResult.indexOf('error',0) == -1){
				// get response content
				WB_OpenApi.WB_search_suggestions_users_out_array wb_out = new WB_OpenApi.WB_search_suggestions_users_out_array();
				WB_OpenApi.WB_search_suggestions_users_out_array arr = wb_out.parse(jsonResult); 
				user_list = arr.lst_data;
			}
		}
		catch(Exception e){
			 ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, e.getMessage()));
		}
	}
	
	// ---------------- Login Page ------------------

	public string weibo_login_url{get {
		WB_OpenApi.WB_oauth2_authorize_in oauth2 = new WB_OpenApi.WB_oauth2_authorize_in();
		return oauth2.toRequestUrl();
	}set;}
	
	// ---------------- Display content Page ------------------
	public List<WB_OpenApi.WB_statuses_user_timeline_out>  content_list{get;set;}
	public void RequestUserProfile(string weibouid){
		WB_OpenApi.WB_users_show_in wb_in = new WB_OpenApi.WB_users_show_in(); 
		wb_in.uid = weibouid;
		string req = wb_in.toRequestUrl();
		string jsonResult = WBUtil.sendRequest(req,'GET');
		if(jsonResult.indexOf('error',0) == -1){
			// get response content
			WB_OpenApi.WB_users_show_out wb_out = new WB_OpenApi.WB_users_show_out();
			user_profile = wb_out.parse(jsonResult); 
		}
	}
	public void RequestContent(string weibouid){
		WB_OpenApi.WB_statuses_user_timeline_in wb_in = new WB_OpenApi.WB_statuses_user_timeline_in(); 
		wb_in.uid = weibouid;
		string req = wb_in.toRequestUrl();
		string jsonResult = WBUtil.sendRequest(req,'GET');
		if(jsonResult.indexOf('error',0) == -1){
			// get response content
			WB_OpenApi.WB_statuses_user_timeline_out_array wb_out = new WB_OpenApi.WB_statuses_user_timeline_out_array();
			WB_OpenApi.WB_statuses_user_timeline_out_array arr = wb_out.parse(jsonResult); 
			content_list = arr.statuses;
		}
	}
}